## quit opened simulation session 
quit -sim

## set customer parameter
set ENABLE_LOOPBACK 0


#################################################
#### 1. setup simulation working library
vlib work
vdel -lib work -all
vlib work


#################################################
#### 2. compile simulation source files into working library
# compile vendor independent files
vlog -work work ../../src/rtl/top/mac_top.v

# compile testbench files
vlog -work work -sv testbench/top_bench.v

# compile bfm files
vlog -work work bfm/phy_rgmii_bfm.v


#################################################
#### 3. start simulation session on top-level testbench with parameters
if {$ENABLE_LOOPBACK==1} {
    set interconnect_config 1
} else {
    set interconnect_config 2
}

vsim top_bench \
     -novopt \
     -t ps \
     -G/top_bench/bfm_rgmii/CLK_CYCLE=8 \
     -G/top_bench/bfm_rgmii/INTERCONNECT_MATRIX=$interconnect_config \
     -G/top_bench/bfm_rgmii/DELAY=1 \
     -G/top_bench/bfm_rgmii/CAPTURE_PKT_NUM=1 \
     -G/top_bench/bfm_rgmii/PREAMBLE_NUM=6

	 
#################################################
#### 4. set simulation run-time parameters
global IgnoreWarning
set IgnoreWarning 1 

log -r */*
radix -hexadecimal


#################################################
#### 5. load waveform window with pre-set watch signals
if {$ENABLE_LOOPBACK==1} {
    do wave_loopback.do
} else {
    do wave.do
}


#################################################
#### 6. let simulation run until break signal reached
run -all
